<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :footer="null"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <div>
        <a-card >
          <span slot="title" >
              销售订单号：{{record.soNo}}
          </span>
          <span slot="extra" >
          状态：
            <span v-if="record.ioflag=='1'"><a-tag color="red">未推送</a-tag></span>
            <span v-if="record.ioflag=='0'"><a-tag color="green">已推送</a-tag></span>
            <span v-if="record.ioflag!='1'&&record.ioflag!=0"><a-tag color="red">推送错误</a-tag></span>
          </span>
          <a-steps :current="current" size="small" labelPlacement="vertical">
            <a-step title="新建"  />
            <a-step title="设计" />
            <a-step title="生产中" />
            <a-step title="成品检验中"  />
            <a-step title="待发货"  />
            <a-step title="部分发货"  />
            <a-step title="发货完成"  />
            <a-step title="完成"  />
          </a-steps>
        </a-card>
      </div>
      <div>
        <a-card title="销售订单详情" >
          <detail-list>
            <detail-list-item term="采购方总部编码">{{record.purchaserHqCode}}</detail-list-item>
            <detail-list-item term="销售订单号">{{record.soNo}}</detail-list-item>
            <detail-list-item term="供应商编码">{{record.supplierCode}}</detail-list-item>
            <detail-list-item term="采购方编码">{{record.buyerCode}}</detail-list-item>
            <detail-list-item term="采购方公司省份">{{record.buyerProvince}}</detail-list-item>
            <detail-list-item term="销售与采购订单的关系" >
              <span v-if="record.soRelType=='1'">
                关联到采购订单
              </span>
              <span v-if="record.soRelType=='2'">
                关联到采购订单行项目
              </span>
              <span v-if="record.soRelType=='0'">
                无关联
              </span>
            </detail-list-item>
            <detail-list-item term="品类编码">{{record.categoryCode}}</detail-list-item>
            <detail-list-item term="种类编码">{{record.subclassCode}}</detail-list-item>
            <detail-list-item term="销售订单状态">{{record.soStatus}}</detail-list-item>
            <detail-list-item term="数据来源">{{record.dataSource}}</detail-list-item>
            <detail-list-item term="来源创建时间">{{record.dataSourceCreateTime}}</detail-list-item>
            <detail-list-item term="是否已推送">
              <span v-if="record.ioflag=='1'">
                未推送
              </span>
              <span v-if="record.ioflag=='0'">
                已推送
              </span>
            </detail-list-item>
            <detail-list-item term="错误信息">{{record.message}}</detail-list-item>
            <detail-list-item term="推送时间">{{record.pushTime}}</detail-list-item>
          </detail-list>
        </a-card>
      </div>

    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import DetailList from '@/components/tools/DetailList'
  const DetailListItem = DetailList.Item
  
  export default {
    name: "ZxjEipXsddModal",
    components: { 
      JDate,
    },
    components: {
      DetailList,
      DetailListItem
    },
    record:{},
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        current:0,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        purchaserHqCode:{rules: [{ required: true, message: '请输入采购方总部编码，国家电网：sgcc!' }]},
        soNo:{rules: [{ required: true, message: '请输入销售订单号!' }]},
        supplierCode:{rules: [{ required: true, message: '请输入供应商编码，即厂商编码!' }]},
        buyerCode:{rules: [{ required: true, message: '请输入采购方编码!' }]},
        buyerProvince:{rules: [{ required: true, message: '请输入采购方公司省份，不带省字!' }]},
        soRelType:{},
        categoryCode:{rules: [{ required: true, message: '请输入品类编码!' }]},
        subclassCode:{rules: [{ required: true, message: '请输入种类编码!' }]},
        soStatus:{rules: [{ required: true, message: '请输入销售订单状态!' }]},
        dataSource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        dataSourceCreateTime:{rules: [{ required: true, message: '请输入来源数据创建时间!' }]},
        isDeleted:{rules: [{ required: true, message: '请输入删除标志 1.是，0.否!' }]},
        supplierSoNo:{rules: [{ required: true, message: '请输入供应商销售订单号，来自供应商!' }]},
        soItemNo:{rules: [{ required: true, message: '请输入销售订单行项目号!' }]},
        supplierSoRelType:{},
        productCode:{rules: [{ required: true, message: '请输入物资编码!' }]},
        productName:{rules: [{ required: true, message: '请输入物资名称!' }]},
        productUnit:{rules: [{ required: true, message: '请输入物资单位!' }]},
        productAmount:{rules: [{ required: true, message: '请输入物资数量!' }]},
        productIdGrpNo:{},
        planDeliveryDate:{rules: [{ required: true, message: '请输入采购订单厂家计划交货日期!' }]},
        planDeliveryPlace:{rules: [{ required: true, message: '请输入采购订单厂家发货地点!' }]},
        planDeliveryPlaceDesc:{},
        ioflag:{rules: [{ required: true, message: '请输入1：未读（默认状态）0：成功；!' }]},
        message:{},
        status:{},
        transno:{},
        orderId:{rules: [{ required: true, message: '请输入orderId!' }]},
        eipPoNo:{},
        ownerId:{rules: [{ required: true, message: '请输入数据拥有方!' }]},
        openId:{rules: [{ required: true, message: '请输入数据可见方!' }]},
        pushTime:{},
        },
        url: {
          add: "/zxjEipXsdd/zxjEipXsdd/add",
          edit: "/zxjEipXsdd/zxjEipXsdd/edit",
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'purchaserHqCode','soNo','supplierCode','buyerCode','buyerProvince','soRelType','categoryCode','subclassCode','soStatus','dataSource','dataSourceCreateTime','isDeleted','supplierSoNo','soItemNo','supplierSoRelType','productCode','productName','productUnit','productAmount','productIdGrpNo','planDeliveryDate','planDeliveryPlace','planDeliveryPlaceDesc','ioflag','message','status','transno','orderId','eipPoNo','ownerId','openId','pushTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'purchaserHqCode','soNo','supplierCode','buyerCode','buyerProvince','soRelType','categoryCode','subclassCode','soStatus','dataSource','dataSourceCreateTime','isDeleted','supplierSoNo','soItemNo','supplierSoRelType','productCode','productName','productUnit','productAmount','productIdGrpNo','planDeliveryDate','planDeliveryPlace','planDeliveryPlaceDesc','ioflag','message','status','transno','orderId','eipPoNo','ownerId','openId','pushTime'))
      },
      addModal (record) {
        if(record.soStatus){
          this.current=parseInt(record.soStatus)-1
        }else{
          this.current=0
        }
        this.record=record;
        this.visible = true;
      }
    }
  }
</script>
<style scoped>
.ant-steps-item{
  width: 87px;
}
</style>